﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media;
using System.Windows;
using System.Windows.Controls;

namespace PatternLockControl.Code
{
    public class SquarePattern : PatternDesignBase
    {
        #region Data
        #region SquareProperty
        private Border _Square;
        public Border Square
        {
            get
            { return _Square; }
            set
            {
                if (_Square == value)
                {
                    return;
                }
                _Square = value;
                RaisePropertyChanged("Square");
            }
        }
        #endregion

        /// <summary>
        /// Sets or gets the Zindex Value for Icon
        /// </summary>
        public override int ZIndexVal
        {
            get { return (int)Square.GetValue(Canvas.ZIndexProperty); }
            set { Square.SetValue(Canvas.ZIndexProperty, value); }
        }

        #region BorderColProperty
        private Color _BorderCol;
        public Color BorderCol
        {
            get
            { return _BorderCol; }
            set
            {
                if (_BorderCol == value)
                {
                    return;
                }
                _BorderCol = value;
                RaisePropertyChanged("BorderCol");
                BorderBrush = new SolidColorBrush(_BorderCol);
            }
        }
        #endregion

        #region BorderBrushProperty
        private SolidColorBrush _BorderBrush;
        public SolidColorBrush BorderBrush
        {
            get
            { return _BorderBrush; }
            private set
            {
                if (_BorderBrush == value)
                {
                    return;
                }
                _BorderBrush = value;
                RaisePropertyChanged("BorderBrush");
            }
        }
        #endregion

        public int Row { get; set; }

        public int Column { get; set; }
        #endregion

        #region Constructor
        public SquarePattern(int row, int column, int width, int value, Color fillNormal, Color fillSelected, Color borderCol)
            : base(fillNormal, fillSelected, value)
        {
            this.FillColNormal = fillNormal;
            this.BorderCol = borderCol;
            this.Row = row;
            this.Column = column;
            Square = new Border() { Name = string.Concat(row, column), Width = width, Height = width, Background = this.FillBrushNormal, BorderBrush = BorderBrush, BorderThickness = new Thickness(2) };
            ZIndexVal = 1;
        } 
        #endregion

        #region Methods
        public override void GridPosition(int row, int col)
        {
            Square.SetValue(Grid.RowProperty, row);
            Square.SetValue(Grid.ColumnProperty, col);
        }
        public override void MarkAsSelected()
        {
            this.Square.Background = FillBrushSelected;
        }
        #endregion
    }
}
